package demo.noi;

import java.util.HashMap;
import java.util.Map;

public class P1_2 {

    public static void main(String[] args) {
        P1_2 p1_2= new P1_2();
        int[] ints = p1_2.twoSum(new int[]{3, 2, 4}, 6);
        System.out.printf("%s,%s%n",ints[0],ints[1]);
    }
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> m = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int a = nums[i];
            if (m.get(nums[i]) != null) {
                return new int[]{i, m.get(nums[i])};
            }
            m.put(target - a, i);
        }
        return new int[]{-1, -1};
    }

}
